package com.example.administrator.shihuo.adapters;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

import java.util.List;

/**
 * Created by Administrator on 2016/5/11.
 */
public class HomePagerVPAdapter extends FragmentPagerAdapter {
    private static final String TAG = HomePagerVPAdapter.class.getSimpleName();
    // 数据源
    private List<Fragment> fragments;

    // 构造
    public HomePagerVPAdapter(FragmentManager fm,List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    /**
     *  根据position获取对应的Fragment
     */
    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    /**
     *  获取数据源的个数
     */
    @Override
    public int getCount() {
        // 三目运算  如果数据源不为null，返回数据源个数，如果为null返回0
        Log.e(TAG, "三目运算");
        return fragments != null ? fragments.size() : 0;
    }

}
